Data Server Users Meeting
11/16/22
Declaration
I am just a light user of Stata
Frame is a new feature/function introduced in Stata 16.
A data object used to store and present data.
It usually contains a two-dimensional, size-mutable, potentially heterogeneous tabular data.
There are variations of data frame. For example, depending on the packages used in R, data frame is called data.frame (base R), data.table (data.table) or tibble (tidyverse). In Python, it is DataFrame (pandas).
Even an Excel sheet is a data frame with limited features.
In Stata, it is frame(s).
Ideally, with a data frame, a user can:
What will you do
when you need to check some data and do some analyses, but the needed data are stored in two or more different files?
The main functionality of frame in Stata is to enable loading and processing multiple data sets within a single Stata program window.
Data in different data sets can communication to each other in certain ways.
More flexibility of saving data processing and analyzing results.
There is a new attribute Frame: {Name} in the Data Properties.
The default frame name is default.
All commands start with frame (or frames)
When multiple frames exist, any command will apply to the current working frame if frame prefix is not used.
How to check the current frame?
frame or pwf (print working frame) (remember pwd?)If we want to change from the current frame old to the new frame, use frame change new.
or cwf new (change working frame) (remember cd?)
One or ALL, there is no some
can’t drop a number of frames at a time
After create a new frame, there are two ways to interact with the frame.
Use frame prefix command: frame framename:
If two frames are relational data sets, they can be linked using frlink (frame link?) command.
Linking two frames is different from merging them together.
The two frames have to be in one-to-one (1:1) or many-to-one (m:1) relation.
🙅 one-to-many (1:m) relation is not allowed in frlink
Let frame one and two have the same variable key, and they have a 1:1 relation.
When one is the current working frame:
frlink 1:1 key, frame(two)
frlink creates a new variable two in the current working frame as the relation indicator.
The indicator variable’s name can be manually set:
frlink 1:1 key, frame(two) gen(flag)
demo
After linking two frames, variable(s) in the linked frame can be retrieved/merged into the current working frame using frget (frame get?) command.
Basic: frget var1 var2, from(two)
Advanced: frget new1=var1, new2=var2, from(two)
demo
Using frval (frame variable?) to access/use a variable in the linked frame without merging it into the current working frame.
This feature is useful in analyzing multi-level data (e.g., student-school-district)
demo
frame post lets you store analyzing results to a non-working frame.
Basic: frame post newframe (exp1) (exp2) (exp3)
What happens?
the values of (exp1), (exp2), and (exp3) are sent to and stored in newframe.
⚠️ In this case, there must be three variables pre-created in newframe
demo
frame post……right?
No worries!
Life will find a way.
frame post is too complicated and not handy.
There are always awesome people in the world!
Elwyn Davies wrote a function framesave to make things eaiser.
The easy way:
framesave newframe: (do some Stata things)
No frame create and frame post are required! 🎉
demo
Frame(s) in Stata:
(personal opinion)
The functionality of processing multiple data sets simultaneously.
An alternative way to link/merge different data sets.
A convenient way to store and manage analyzing results.
Others (search online to find more use cases.)
(personal opinion)
Inconvenient in checking frames and their data.
Commands are relatively complicated, tedious, and sometimes inconsistent.
Data Server Users Meeting